module.exports = function ($scope, $resource, $modal, toaster) {

	//游客信息列表
	$scope.search = function(pageNo) {
		var para = {
			'pageNo': pageNo || $scope.currentPage,
			'pageSize': $scope.itemsPerPage,
			'name': $scope.searchform.name,
			'card_no': $scope.searchform.card_code,
			'date': date2str2($scope.searchform.date.lable).replace(/-/g, '')
		}
		$resource('/api/as/atc/tourist/getTourist2List', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
				$scope.touristList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
				$scope.currentPage = pageNo;
            } else {
                toaster.error({title: '', body: '查询电子票游客失败'});
            }
        });
	}

	init();
	function init(){
		$scope.currentPage = 1;			//当前页码
		$scope.itemsPerPage = 20;		//每页显示几条
		$scope.searchform = {
			'date': {
				'lable': date2str2(new Date()),
				'opened': false
			}
		};
		$scope.search(1);
	}

	//游客的出游信息
	$scope.getInfo = function(item) {
		var modalInstance = $modal.open({
			template: require('../views/touristTravels.html'),
			controller: 'touristTravels',
			size: 'lg',
			resolve: {
				item: function () {
					return item;
				}
			}
		});
	}


	//打开日历空间,选择时间
	$scope.dateOpen = function ($event, item) {
		$event.preventDefault();
		$event.stopPropagation();
		item.opened = true;
	};

	//日期转字符串
	function date2str2(d) {
		if (d === undefined) {
			return "";
		}
		if(typeof d === 'string'){
			return d;
		}
		var month = (d.getMonth() + 1).toString();
		var day = d.getDate().toString();
		if (month.length == 1) month = '0' + month;
		if (day.length == 1) day = '0' + day;
		return d.getFullYear() + "-" + month + "-" + day;
	}

};